<template>
	<view class="page">
		<view class="head"><view class="orderTitle">订单详细</view></view>
		<view class="body">
			<view class="orderContent">{{ orderContent }}</view>
			<view class="orderPrice">
				<view class="orderPriceTitle">付款金额</view>
				<view class="orderPriceText">￥{{ orderPriceFormat(orderPrice) }}</view>
			</view>
			<view class="orderPaySelect">
				<view class="orderPaySelectTitle">选择支付方式</view>
				<view class="orderPayItem">
					<radio-group name="">
						<label class="orderPayItemLabel">
							<radio value="11111" checked="true" class="orderPayItemRadio"/>
							<image src="../../static/icos/wxpay.png" mode="aspectFill" class="orderPayItemImg"></image>
							<text class="orderPayItemText">微信支付</text>
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		<view class="bottom">
			<view class="orderPayButton" @click="payOrder()">立即支付</view>
		</view>
	</view>
</template>

<script>
import { moneyFormat } from '../../common/common.js';
export default {
	data() {
		return {
			vipInfoId: 0,
			orderContent: '',
			orderPrice: 0
		};
	},
	onLoad(option) {
		this.vipInfoId = option.id;
		this.getUserVIPRedView(this.vipInfoId);
	},
	methods: {
		getUserVIPRedView(id) {
			this.$api.getUserVIPRedView({ id: id }).then(res => {
				console.log(res);
				this.orderContent = res.data.Title;
				this.orderPrice = res.data.Price;
			});
		},
		payOrder(){
			this.$api.postUserVipRedOrder({id: this.vipInfoId, openid: getApp().globalData.openid}).then(res => {
				console.log(res)
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: res.data.TimeStamp,
					nonceStr: res.data.Nonce_str,
					package: res.data.Prepay_id,
					signType:"MD5",
					paySign:res.data.Sign,
					orderInfo:{
						appid:getApp().globalData.openAppId,
						noncestr:res.data.Nonce_str,
						package:"Sign=WXPay", // 固定值
						partnerid:'123123123', // 微信支付商户号
						prepayid:'123123123123',  // 统一下单订单号
						timestamp:res.data.TimeStamp,
						sign:res.data.Sign,
					},
					success:(res) => {
						uni.showToast({
							title:"支付成功",
							icon:"success",
							duration:3000,
							complete:function(){
							    uni.reLaunch({
							        url: '/pages/release/release'
							    });
								// uni.switchTab({
								//     url: '/pages/release/release'
								// });
							}
						});
					},
					fail:(res) => {
						// console.log(JSON.stringify(res));
						uni.showToast({
							title: '支付失败',
							icon: "error",
							duration: 3000,
							// complete: function () {
							//     wx.reLaunch({
							//         url: '/pages/release/release'
							//     });
							// }
						});
					}
				});
			})
		},
		orderPriceFormat(price) {
			return moneyFormat(price, 2);
		}
	}
};
</script>

<style scoped>
@import url('regView.css');
</style>
